package com.shd.edanpei.presenter;

import android.text.TextUtils;


import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.base.network.model.NoDataResponse;
import com.shd.edanpei.base.network.rx.BaseObserver;
import com.shd.edanpei.base.network.rx.RxTransformer;
import com.shd.edanpei.util.ToastUtil;
import com.shd.edanpei.presenter.contract.OpinionContract;

import io.reactivex.android.schedulers.AndroidSchedulers;


/**
 * Created by mc on 2018/3/29.
 * yang-wen-wen
 */
public class OpinionPresenter extends BasePresenterImpl<OpinionContract.OpinionIView>
        implements OpinionContract.OpinionIPresenter {

    public OpinionPresenter(OpinionContract.OpinionIView mView) {
        super(mView);
    }

    @Override
    public void submit(String content) {
        if (TextUtils.isEmpty(content)) {
            ToastUtil.showToast("还未输入您的意见哟");
            return;
        }
        mBaseIView.showLoading("");
        ApiCreator.getApi().suggest(content)
                .compose(RxTransformer.<NoDataResponse>errorHandle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<NoDataResponse>() {
                    @Override
                    protected void onSuccess(NoDataResponse data) {
                        ToastUtil.showToast("意见反馈成功");
//                        Preference.setData(OPINION, null);
                        mBaseIView.getContext().finish();
                    }

                    @Override
                    public void onFinish() {
                        mBaseIView.stopLoading();
                    }
                });
    }
}
